package com.lhb.aicodemother.ai.core.saver;

import cn.hutool.core.util.StrUtil;
import com.lhb.aicodemother.ai.model.MultiFileCodeResult;
import com.lhb.aicodemother.ai.model.enums.CodeGenTypeEnum;
import com.lhb.aicodemother.exception.BusinessException;
import com.lhb.aicodemother.exception.ErrorCode;

/*
*多文件代码保存器
* */
public class MultiFileCodeFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult> {
    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void saveFile(MultiFileCodeResult result, String basePath) {
        //写入HTML代码
        writeToFile(basePath,"index.html",result.getHtmlCode());
        // 写入CSS代码
        writeToFile(basePath,"style.css",result.getCssCode());
        // 写入JS代码
        writeToFile(basePath,"script.js",result.getJsCode());
    }

    @Override
    protected void validateInput(MultiFileCodeResult result){
        super.validateInput(result);
        if(StrUtil.isBlank(result.getHtmlCode())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"HTML代码不能为空");
        }
    }
}
